package skcomms.NateOnBiz.activity.chat;

import android.os.Bundle;
import skcomms.NateOnBiz.activity.ShowMsg;
import skcomms.NateOnBiz.common.BundleIds;
import skcomms.NateOnBiz.manager.ChatManager;
import skcomms.NateOnBiz.observer.ObserverEventNotifier;
import skcomms.NateOnBiz.observer.ObserverEventSubscriber;
import skcomms.NateOnBiz.observer.event.ChatNotifyEvent;
import skcomms.NateOnBiz.observer.event.ObserverEvent;

/**
 * not used currently 
 * 
 * @author hyunsik
 */
public class ShowChatMsg extends ShowMsg implements ObserverEventSubscriber {
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
    	ObserverEventNotifier.getInstance().subscribeForEvent(this, ChatNotifyEvent.NAME);
    	super.onCreate(savedInstanceState);
	}
	
	public void onDestroy() {
		ObserverEventNotifier.getInstance().unSubscribeFromEvent(this, ChatNotifyEvent.NAME);
		super.onDestroy();
	}
	
	protected void onClickLeftButton() {
		ChatManager.getInstnace().startChatActivity(this, getIntent().getStringExtra(BundleIds.SS_SESSION_KEY));
	}
	
	@Override
	public void receiveReaderEvent(ObserverEvent event) {
		if(event.getName().equals(ChatNotifyEvent.NAME)) {
			final ChatNotifyEvent chatNotifyEvent = (ChatNotifyEvent) event;
			new Thread(new Runnable() {
			    @Override
			    public void run() {    
			        runOnUiThread(new Runnable(){
			            @Override
			             public void run() {
			            	setContent(chatNotifyEvent.getChatMessageData().getMessage());
			             }
			        });
			    }
			}).start();
		}
	}

}
